/**
 *
 */
package st.yushao.restaurant.fw;

import java.util.Map;

import org.apache.struts2.ServletActionContext;

import st.yushao.restaurant.exception.UnAuthorizedException;
import st.yushao.restaurant.fw.AbstractBaseAction.KEYS;
import st.yushao.restaurant.vo.UserVO;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;

/**
 * @author acer
 *
 */
public class LoginInterceptor extends AbstractInterceptor {

    /**
     * serialVersionUID
     */
    private static final long serialVersionUID = -1872404594207818180L;

    /* (non-Javadoc)
     * @see com.opensymphony.xwork2.interceptor.AbstractInterceptor#intercept(com.opensymphony.xwork2.ActionInvocation)
     */
    @Override
    public String intercept(ActionInvocation ai) throws Exception {

        ActionContext ac = ai.getInvocationContext();
        Map<String, Object> session = ac.getSession();
        UserVO uvo = (UserVO) session.get(KEYS.CUR_USER);
        String url = ServletActionContext.getRequest().getRequestURI();
        if (uvo == null) {
            throw new UnAuthorizedException();
        }

        return ai.invoke();
    }

}
